﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar;
using DevComponents.Editors;

namespace Einstein.Utility
{
    public static class ComboBoxExExt
    {
        /// <summary>
        /// 根据键设置选择项
        /// </summary>
        /// <param name="comboBox"></param>
        /// <param name="value"></param>
        public static void SelectedByValue(this ComboBoxEx comboBox, object value)
        {
            for (int i = 0; i < comboBox.Items.Count; i++)
            {
                ComboItem it = comboBox.Items[i] as ComboItem;
                if (it != null && it.Value != null && it.Value.ToString() == value.ToString())
                {
                    comboBox.SelectedIndex = i;
                    break;
                }
            }
        }
        /// <summary>
        /// 根据值设置选择项
        /// </summary>
        public static void SelectedByText(this ComboBoxEx comboBox, string text)
        {
            for (int i = 0; i < comboBox.Items.Count; i++)
            {
                ComboItem it = comboBox.Items[i] as ComboItem;
                if (it != null && it.Text == text)
                {
                    comboBox.SelectedIndex = i;
                    break;
                }
            }
        }
    }
}
